#include "logfile.h"
#include <time.h>


const char cLogFile[] = "c:\\logfile.log";

CLogFile::CLogFile(void)
{
	m_pFile = NULL;
}

CLogFile::~CLogFile(void)
{
	if(m_pFile)
		fclose(m_pFile);
	m_pFile = NULL;
}

void CLogFile::Add(const char* format, ...)
{
	if(!m_pFile) 
		m_pFile = fopen(cLogFile, "a");
	if(!m_pFile) 
		return;
	XString c;
	tm *pt;
	time_t tt;
	time(&tt);
	pt = gmtime(&tt);
	
	va_list marker;
	va_start(marker, format);

	c.FormatV(format, marker);
	fprintf(m_pFile, "%02d:%02d:%02d  %s\n", pt->tm_hour, pt->tm_min, pt->tm_sec, (const char*)c );
	
	va_end(marker);

	fclose(m_pFile);
	m_pFile = NULL;
}

